<?php
/**
* @package Scribble
* @subpackage SkeletonApp
*/
use Buan\View;
class ScribbleTemplate_sampleSimple extends ScribbleTemplate implements IScribbleTemplate {

	/**
	* Gathers content from the given array and builds a StdClass object that will
	* be saved to the Page.
	*
	* @param array Content
	* @return \StdClass
	*/
	public function gatherPopulatorData(PageModel $page, $data=array()) {

		// Gather
		$data = isset($data['inner']) ? $data['inner'] : array();
		$content = new StdClass();
		$content->heading = isset($data['heading']) ? $data['heading'] : '';
		$content->content = isset($data['content']) ? $data['content'] : array();

		// Result
		return $content;
	}

	/**
	* Returns the front-end template.
	*
	* @param PageModel Page to render
	* @return ScribblePublicView
	*/
	public function getFrontEndView(PageModel $page) {
		$view = new ScribblePublicView();
		$view->setSource($this->getBaseFolder().'/front-end.tpl');
		$view->page = $page;
		$view->baseUrl = $this->getBaseUrl();
		return $view;
	}

	/**
	* Returns the populator template.
	*
	* @param PageModel
	* @return ScribbleAdminView
	*/
	public function getPopulatorView(PageModel $page) {

		// Prep populator view
		$view = new ScribbleAdminView();
		$view->setSource($this->getBaseFolder().'/populator.tpl');
		$view->baseUrl = $this->getBaseUrl();
		$view->page = $page;

		// Result
		return $view;
	}

	/**
	* Returns a short description of this template.
	*
	* @return string
	*/
	public function getShortDescription() {
		return "Provides a few simple input elements for the most basic of templates";
	}

	/**
	* Return the title of this template.
	*
	* @return string
	*/
	public function getTitle() {
		return 'Sample: Simple';
	}

	/**
	* Return this template type.
	*
	* @return int
	*/
	public function getType() {
		return self::TYPE_INNER;
	}

	/**
	* Validate the data gathered from the input form.
	*
	* @param PageModel Page to validate
	* @param array Stores error messages
	* @return bool
	*/
	public function validatePageContent(PageModel $page, &$messages) {
		$result = TRUE;
		$contentObj = $page->getInnerContent();
		if($contentObj->content->heading=='') {
			$messages[] = 'Invalid heading';
			$result = FALSE;
		}
		return $result;
	}
}
?>